<?php

// Insert into SC_FORMULA (FORMULA_ID,SEQUENCE,TYPE,CODE,CLASS,DESCRIPTION,START_DATE,END_DATE,PCNT_TAX,LINE_ORDER)
//values (XX,1,'SHIPPING_COST','ShippingFixedPrice','CartWS_Model_FormulaEngine_Formula_ShippingFixedPrice','Costo de envio fijo $10',to_timestamp('16-SEP-09','DD-MON-RR HH.MI.SSXFF AM'),null,1,1000);

class CartWS_Model_FormulaEngine_Formula_ShippingPriceSucursal extends CartWS_Model_FormulaEngine_Formula_Abstract {

    public function execute() 
    {       
            // Formula Properties
            $rowSet = $this->getProperties();
            if( count( $rowSet )) {
                $i=0;
                $result = array();
                foreach( $rowSet as $row ) {
                    $result[$i] = $row->toArray();
                    $i++;
                }
            }
            $formulaProperties = $result;
            $result = array();
    
            foreach( $formulaProperties as $property )
            {
                $result[$property['property']] = $property['value'];
            }
            $formulaProperties = $result;

            // Informacion de la orden
            $row = $this->getOrder();
            $orderInfo = $row->toArray();

            if ( $orderInfo['shipping_method_id'] == null )
            {
                // No esta seteado el metodo de envio
                return CartWS_Model_FormulaEngine_Formula_Abstract::RET_CONTINUE;
            }

            if ( $orderInfo['shipping_method_id'] == $formulaProperties['shippingMethodId'] )
            {
                $this->clearMyAmount();
                return CartWS_Model_FormulaEngine_Formula_Abstract::RET_STOP;
            }
    
            return CartWS_Model_FormulaEngine_Formula_Abstract::RET_CONTINUE;
    }    
}
